package com.dj.web.password.controller;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.dj.web.utils.DaijiaWebUserUtil;

/**
 * 注册
 * 
 * @author jaen.hsu.cn@gmail.com 2012-4-19 下午1:23:24
 */
@Controller
public class PasswordController {

    @RequestMapping(method = RequestMethod.GET, value = "/password")
    public String password(Model model, HttpServletRequest request) {
        // 未登录
        if (!DaijiaWebUserUtil.isLogon(request)) {
            return "redirect:/login.htm?done=password.htm";
        }
        model.addAttribute(new PasswordForm());
        return "/profile/password";
    }

    @RequestMapping(method = RequestMethod.POST, value = "/password")
    public String modifyPassword(@Valid PasswordForm regUserForm, BindingResult result, HttpServletRequest request) {
        // 已登录
        if (!DaijiaWebUserUtil.isLogon(request)) {
            return "/login";
        }
        if (result.hasErrors()) {
            return "/profile/password";
        }
        // TODO:操作成功页面
        return "/index";
    }
}
